package com.fly.snailrun.access.controller;

import com.fly.snailrun.base.web.ResponseVo;
import com.fly.snailrun.business.DraftFileService;
import com.fly.snailrun.domain.dto.DraftFileGenerateDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

/**
 * @author：gaoxu
 * @date：Created in 2024/7/25 14:34
 */
@RestController
@RequestMapping("/file")
@Api(tags = "剪映模板相关API")
public class DraftFileController {
    private static Logger log = LoggerFactory.getLogger(DraftFileController.class);

    @Autowired
    private DraftFileService draftFileService;

    /**
     * 按照当前模板生成多个草稿文件
     *
     * @param draftNum          生成草稿文件个数
     * @param draftName         草稿文件名
     * @param draftTemplateName 草稿模板文件名
     * @return
     */
    @ApiOperation("按照当前模板生成多个草稿文件")
    @RequestMapping(value = "/draft/create/{draftNum}", method = RequestMethod.GET)
    public ResponseVo createDraftFile(@PathVariable(value = "draftNum", required = true) Integer draftNum,
                                      @RequestParam(value = "draftName", required = false) String draftName,
                                      @RequestParam(value = "draftTemplateName", required = false) String draftTemplateName) {
        draftFileService.createDraftFile(draftNum, draftName, draftTemplateName);
        return ResponseVo.creComSucResult();
    }

    /**
     * 按照模板文件下草稿文件生成草稿视频
     *
     * @param draftFileGenerateDto 草稿文件生成dto
     * @param draftFileName        草稿文件名
     * @param draftTemplateName    草稿模板文件名
     * @return
     */
    @ApiOperation("按照模板文件下草稿文件生成草稿视频")
    @RequestMapping(value = "/draft/generate", method = RequestMethod.POST)
    public ResponseVo generateDraftFile(@RequestBody DraftFileGenerateDto draftFileGenerateDto,
                                        @RequestParam(value = "draftFileName", required = false) String draftFileName,
                                        @RequestParam(value = "draftTemplateName", required = false) String draftTemplateName) {
        draftFileService.generateDraftFile(draftFileGenerateDto, draftFileName, draftTemplateName);
        return ResponseVo.creComSucResult();
    }


    /**
     * 删除生成的模板的草稿文件
     *
     * @param draftFileName     草稿文件名
     * @param draftTemplateName 草稿模板文件名
     * @return
     */
    @ApiOperation("删除生成的模板的草稿文件")
    @RequestMapping(value = "/draft/batch/del/{draftFileName}", method = RequestMethod.GET)
    public ResponseVo generateDraftFileBatchDel(@PathVariable(value = "draftFileName", required = false) String draftFileName,
                                                @RequestParam(value = "draftTemplateName", required = false) String draftTemplateName) {
        draftFileService.generateDraftFileBatchDel(draftFileName, draftTemplateName);
        return ResponseVo.creComSucResult();
    }

    /**
     * 根据导出的模板生成douyin的填充文案
     *
     * @param draftFileName
     * @return
     */
    @ApiOperation("生成douyin的填充文案")
    @RequestMapping(value = "/draft/batch/copywriter/{draftFileName}/{draftTemplateName}", method = RequestMethod.GET)
    public ResponseVo generateDouyinCopywriter(@PathVariable(value = "draftFileName", required = false) String draftFileName,
                                               @PathVariable(value = "draftTemplateName", required = false) String draftTemplateName) {
        draftFileService.generateDouyinCopywriter(draftFileName, draftTemplateName);
        return ResponseVo.creComSucResult();
    }


    /**
     * 抖音自动化发布
     *
     * @return The response indicating the success of the operation.
     * @throws IOException          If an I/O error occurs.
     * @throws InterruptedException If the current thread is interrupted while waiting.
     */
    @ApiOperation("抖音作品自动发布触发")
    @RequestMapping(value = "/draft/douyin/publish", method = RequestMethod.GET)
    public ResponseVo douyinPublish() {
        draftFileService.douyinPublish();
        return ResponseVo.creComSucResult();
    }
}
